<template>
  <a-card :bordered="false">
     <div class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="48">
            <a-col :md="8" :sm="24">
              <a-form-item label="用户名称">
                <a-input placeholder="请输入" v-model="queryParam.key"/>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <span class="table-page-search-submitButtons">
                <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
                <a-button style="margin-left: 8px" @click="() => queryParam = { key:null}">重置</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form>
     </div>
     <div class="table-operator">
       <a-button type="primary" icon="plus" @click="handleEdit()">新建</a-button>
     </div>

     <s-table ref="table"  size="default" :rowKey="(record) => record.id"  :columns="columns" :data="loadData">
        <span slot="action" slot-scope="text, record">
           <a @click="handleEdit(record)">编辑</a>
           <a-divider type="vertical" />
           <a-dropdown>
             <a class="ant-dropdown-link">
               更多 <a-icon type="down" />
             </a>
             <a-menu slot="overlay" >
               <a-menu-item>
                 <a @click="handleDelete(record.id)">删除</a>
               </a-menu-item>
             </a-menu>
           </a-dropdown>
        </span>
     </s-table>
  <a-card>
</template>
<script>
  import {findList,deleteOne} from "../../api/${entity.code}";
  import STable from '@/components/Table'

  export default {
    name:"${entity.name}List",
    components:{STable, },
    data(){
      return{
        // 查询参数
        queryParam: {
          key: null,
        },
        // 加载数据方法 必须为 Promise 对象
        loadData: parameter => {
          return findList(Object.assign(parameter, this.queryParam)).then(res => {
            return res.data
          })
        },
        // 表头
        columns: [
      ## for(item in entity.generalList) {
        ## if(item.isId == true){continue;}
        ## if(item.name == "deleted" ){continue;}
        ## if(item.name == "createAt" ){continue;}
        ## if(item.name == "creatorId" ){continue;}
        ## if(item.name == "modifyAt" ){continue;}
        ## if(item.name == "modifierId" ){continue;}
          {
            title: '${item.displayName}',
            dataIndex: '${item.name}'
          },
      ## }
          {
            title: '操作',
            width: '150px',
            dataIndex: 'action',
            scopedSlots: { customRender: 'action' }
          }
        ],
      }
    },
    methods:{
      handleEdit(record){
        if(!record) this.$router.push({name: '${entity.name}Detail'})
        else this.$router.push({name: '${entity.name}Detail',query: {id: record.id}})
      },
      async handleDelete(id) {
          let data = { id:id, }
          let resp = await deleteOne(data)
          if(this.validResp(resp)) {
            this.$message.success('删除成功!');
            this.$refs.table.refresh()
          } else this.$message.warning(resp.msg||'删除失败');
      },
    }
  }
</script>
<style>
</style>
